Python uses English keywords and is highly readable
Essential for software engineering and web development
Supports multiple programming paradigms
No compilation needed - runs directly
Cross-platform compatibility
Perfect for beginners and versatile in application
Features of Python Code
Easy to learn and understand
Simple structure with few keywords
Clear and readable syntax
Easy to maintain and modify
Python Syntax
Now you can start your journey in coding. A question might arise in you: What is syntax? A syntax is a set of rules that define how a Python program should be written.
1
Writing Python Code
There are two methods of writing Python code:
Directly via the command line
By creating a Python file (with the extension .py) in a code editor and running it in the command line
The first method is used for simple scripts or quick tests. The second method is more suitable for larger projects or when you need to maintain and modify your code.
2
Indentation
To differentiate between statements, we use white space or indentation to define each block in the program. When executing a program without proper indentation, Python will give an error because there is no starting space! Proper indentation is crucial for your code to work correctly.
Python uses indentation instead of semicolons to define code blocks
3
Comments
Comments are as important as code because they describe why a piece of code was written. A comment in Python starts with a # sign and ends at the end of the actual line. All characters after the # character until the end of the line are part of the comment and are ignored by the Python interpreter.
4
Variables
In Python, variables are created when they are assigned a value, and there is no command to declare a variable in Python. Variables are automatically created when you assign a value to them.
5
Continuation of Statement
In case of a long statement, it can be extended over several lines using the backslash (\) character. This allows you to write more readable code by breaking long lines into multiple lines.